package xyz.xuminghai.javafx_learn.scene;

import javafx.application.Application;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

/**
 * 2023/1/11 10:14 星期三<br/>
 * <p>
 * 光标样式
 *
 * @author xuMingHai
 */
public class CursorApp extends Application {

    private final ToggleGroup toggleGroup = new ToggleGroup();

    /**
     * 流布局
     */
    private final FlowPane flowPane = new FlowPane(10, 10);

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void init() {
        RadioButton r1 = new RadioButton("默认光标类型");
        r1.setToggleGroup(toggleGroup);
        r1.setUserData(Cursor.DEFAULT);
        r1.setSelected(true);

        RadioButton r2 = new RadioButton("十字光标类型");
        r2.setToggleGroup(toggleGroup);
        r2.setUserData(Cursor.CROSSHAIR);

        RadioButton r3 = new RadioButton("文本光标类型");
        r3.setToggleGroup(toggleGroup);
        r3.setUserData(Cursor.TEXT);

        RadioButton r4 = new RadioButton("等待光标类型");
        r4.setToggleGroup(toggleGroup);
        r4.setUserData(Cursor.WAIT);

        RadioButton r5 = new RadioButton("西南调整大小光标类型");
        r5.setToggleGroup(toggleGroup);
        r5.setUserData(Cursor.SW_RESIZE);

        RadioButton r6 = new RadioButton("东南调整大小光标类型");
        r6.setToggleGroup(toggleGroup);
        r6.setUserData(Cursor.SE_RESIZE);

        RadioButton r7 = new RadioButton("西北调整大小光标类型");
        r7.setToggleGroup(toggleGroup);
        r7.setUserData(Cursor.NW_RESIZE);

        RadioButton r8 = new RadioButton("东北调整大小光标类型");
        r8.setToggleGroup(toggleGroup);
        r8.setUserData(Cursor.NE_RESIZE);

        RadioButton r9 = new RadioButton("向北调整大小光标类型");
        r9.setToggleGroup(toggleGroup);
        r9.setUserData(Cursor.N_RESIZE);

        RadioButton r10 = new RadioButton("向南调整大小光标类型");
        r10.setToggleGroup(toggleGroup);
        r10.setUserData(Cursor.S_RESIZE);

        RadioButton r11 = new RadioButton("向西调整大小光标类型");
        r11.setToggleGroup(toggleGroup);
        r11.setUserData(Cursor.W_RESIZE);

        RadioButton r12 = new RadioButton("向东调整大小光标类型");
        r12.setToggleGroup(toggleGroup);
        r12.setUserData(Cursor.E_RESIZE);

        RadioButton r13 = new RadioButton("一只手张开的光标");
        r13.setToggleGroup(toggleGroup);
        r13.setUserData(Cursor.OPEN_HAND);

        RadioButton r14 = new RadioButton("手掌合拢的光标，通常在“抓取”时使用，例如平移时");
        r14.setToggleGroup(toggleGroup);
        r14.setUserData(Cursor.CLOSED_HAND);

        RadioButton r15 = new RadioButton("手形光标类型，类似于指向的手，通常用于指示可以单击的内容，例如超链接");
        r15.setToggleGroup(toggleGroup);
        r15.setUserData(Cursor.HAND);

        RadioButton r16 = new RadioButton("移动光标类型");
        r16.setToggleGroup(toggleGroup);
        r16.setUserData(Cursor.MOVE);

        RadioButton r17 = new RadioButton("消失光标类型。这通常在拖动某些东西时使用，这样当用户释放鼠标时，该项目就会消失。在 Mac 上，这用于将项目拖出工具栏或其他此类情况");
        r17.setToggleGroup(toggleGroup);
        r17.setUserData(Cursor.DISAPPEAR);

        RadioButton r18 = new RadioButton("水平光标类型");
        r18.setToggleGroup(toggleGroup);
        r18.setUserData(Cursor.H_RESIZE);

        RadioButton r19 = new RadioButton("垂直光标类型");
        r19.setToggleGroup(toggleGroup);
        r19.setUserData(Cursor.V_RESIZE);

        RadioButton r20 = new RadioButton("无光标类型。在不支持自定义光标的平台上，这将与DEFAULT相同");
        r20.setToggleGroup(toggleGroup);
        r20.setUserData(Cursor.NONE);

        flowPane.getChildren().addAll(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10,
                r11, r12, r13, r14, r15, r16, r17, r18, r19, r20);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("CursorApp");
        Scene scene = new Scene(flowPane, 800, 600);
        // 设置默认光标
        scene.setCursor((Cursor) toggleGroup.getSelectedToggle().getUserData());
        // 属性修改监听
        toggleGroup.selectedToggleProperty()
                .addListener((observable, oldValue, newValue) ->
                        scene.setCursor((Cursor) newValue.getUserData()));

        primaryStage.setScene(scene);
        primaryStage.show();
    }

}
